bytecodes = new File("bytecode.txt")
OpCodes = new File("OpCode.java")
OpCodes.delete()

OpCodes.write("public enum OpCode {\n")

bytecodes.eachLine {

	line = it.split(' ')
	men = line[1]
	name = men.toUpperCase()
	cpcode = line[0]
	paramcount = 0
	if (line.size() == 3) {
		paramcount = line[2]
	}

	OpCodes.append '\t' +name + '(' + cpcode + ', "' + men + '", '  + paramcount + '),\n'
}

OpCodes.append """private final byte opCode;
private final String memoni;
private final int paramCount;

OpCode(int opCode, String memoni, int paramCount) {
    this.opCode = (byte) opCode;
    this.memoni = memoni;
    this.paramCount = paramCount;
}

public int getOpCode() {
    return opCode;
}

public String getMemoni() {
    return memoni;
}

public static OpCode findBy(byte opCode) {
    for (OpCode codeEnum : values()) {
        if (codeEnum.getOpCode() == opCode) {
            return codeEnum;
        }
    }
    throw new RuntimeException("Unknown Instruction " + opCode);
}

public int getParamCount() {
    return paramCount;
}

public boolean hasParam() {
    return paramCount != 0;
}
 """

OpCodes.append("}\n")

